﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CrossLayerCommunication
{
    public static class MessageExtensions
    {
        public static IMessage AddParams(this IMessage message, params object[] args)
        {
            IMessage resultMessage = (IMessage)message.Clone();

            if (resultMessage.Params == null || resultMessage.Params.Length == 0)
                resultMessage.Params = args;
            else
                resultMessage.Params = resultMessage.Params.Union(args).Distinct().ToArray();

            return resultMessage;
        }

        public static IMessage ClearParams(this IMessage message)
        {
            IMessage resultMessage = (IMessage)message.Clone();

            resultMessage.Params = new object[0];

            return resultMessage;
        }

        public static IMessage ChangeKey(this IMessage message, string newKey)
        {
            IMessage resultMessage = (IMessage)message.Clone();

            resultMessage.Key = newKey;

            return resultMessage;
        }
    }
}
